import request from '@/utils/request'
import type { User, UserParams, PageList } from './model/user'
import qs from 'qs'

// 用户列表分页查询
export const getUserList = async (data: UserParams) => {
  return await request.post<PageList<User>>('/system/user/loadList', {
    data
  })
}

// 修改用户
export const editUser = async (data: User) => {
  return await request.put('/system/user/edit', {
    data
  })
}

// 重置密码
export const resetPwd = async (data: User) => {
  return await request.put('/system/user/resetPwd', {
    data
  })
}

// 状态修改
export const changeStatus = async (data: User) => {
  return await request.put('/system/user/changeStatus', { data })
}

// 新增用户
export const addUser = async (data: User) => {
  return await request.post('/system/user/add', { data })
}

// 删除用户
export const removeUser = async (data: User) => {
  const userIds = data.userId ?? ''
  return await request.delete(`/system/user/${userIds}`)
}

// 修改密码
export const changePwd = async (data: {
  confirmPassWord: string
  oldPassWord: string
  newPassWord: string
  username: string
}) => {
  return await request.post('/system/user/updatePassWord', {
    data: qs.stringify(data)
  })
}
